﻿
using System.Collections.Generic;
using System.Web.Mvc;
using Gx.Bll.Role;
using Gx.Model.Role;
using Gx.Model;
using Gx.Model.Other;

namespace Gx.ZhiChengXianWei.Controllers
{
    public class SystemSetController : Controller
    {
        private readonly M_RoleInfoBll roleBll = new M_RoleInfoBll();
        private readonly M_PageUrlInfoBll pageUrlBll = new M_PageUrlInfoBll();
        private readonly M_RolePageUrlInfoBll rpuBll = new M_RolePageUrlInfoBll();

        public ActionResult RoleList()
        {
            return View();
        }
        /// <summary>
        /// 获取用户数据列表
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="page"></param>
        /// <param name="rows"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult GetRoleInfoList(string roleName, int page, int rows)
        {
            List<M_RoleInfo> list = roleBll.GetRoleInfoList(roleName, page, rows, out int TotalCount);
            return Json(new { total = TotalCount, rows = list });
        }

        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult AddRoleInfo(M_RoleInfo model)
        {
            ReturnModel r = roleBll.AddRoleInfo(model);
            return Json(r);
        }

        [HttpPost]
        public ActionResult DelRoleInfo(int roleId)
        {
            ReturnModel r = roleBll.DelRoleInfo(roleId);
            return Json(r);
        }

        /// <summary>
        /// 修改数据
        /// </summary>
        [HttpPost]
        public ActionResult EditRoleInfo(M_RoleInfo model)
        {
            ReturnModel r = roleBll.EditRoleInfo(model);
            return Json(r);
        }

        [HttpPost]
        public JsonResult GetRoleInfJson()
        {
            List<M_RoleInfo> roleList = roleBll.GetRoleInfoList();
            return Json(roleList);
        }


        public ActionResult PageUrlList()
        {
            return View();
        }

        /// <summary>
        /// 获取页面树形结构
        /// </summary>
        /// <returns></returns>
        public JsonResult GetPageUrlTreeView()
        {
            return Json(pageUrlBll.GetPageUrlJson());
        }

        [HttpPost]
        public JsonResult GetPageUrlInfoJson()
        {
            List<TreeView> puList = pageUrlBll.GetPageUrlInfoCombotree();
            return Json(puList);
        }

        /// <summary>
        /// 新增页面权限
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult AddPageUrlInfo(M_PageUrlInfo model)
        {
            ReturnModel r = pageUrlBll.AddPageUrlInfo(model);
            return Json(r);
        }

        [HttpPost]
        public ActionResult EditPageUrlInfo(M_PageUrlInfo model)
        {
            ReturnModel r = pageUrlBll.EditPageUrlInfo(model);
            return Json(r);
        }

        [HttpPost]
        public ActionResult DelPageUrlInfo(string id)
        {
            ReturnModel r = pageUrlBll.DelPageUrlInfo(id);
            return Json(r);
        }

        public ActionResult RolePageUrlIndex()
        {
            return View();
        }

        [HttpPost]
        public JsonResult GetRoleJson()
        {
            List<TreeView> tvList = roleBll.GetRoleJson();
            return Json(tvList);
        }

        [HttpPost]
        public JsonResult GetPageUrlJson(int? roleId)
        {
            return Json(pageUrlBll.GetPageUrlJson(roleId));
        }

        [HttpPost]
        public ActionResult AddPagePurviews(int roleId, string pageId)
        {
            ReturnModel r = rpuBll.InsertRolePageUrlInfo(roleId, pageId);
            return Json(r);
        }

    }
}
